from sqlalchemy import String, SmallInteger, ForeignKey
from sqlalchemy.orm import mapped_column, Mapped, relationship

from models import BaseTable


class MqttClientTable(BaseTable):
    __tablename__ = "mqtt_client"

    clientId: Mapped[str] = mapped_column(String(32), nullable=True, comment="mqtt客户端唯一id")
    name: Mapped[str] = mapped_column(String(32), unique=True, comment="客户端名称")
    comType: Mapped[str] = mapped_column(String(16), default="mqtt", comment="连接类型")
    host: Mapped[str] = mapped_column(String(32), comment="mqtt服务器地址")
    port: Mapped[int] = mapped_column(comment="mqtt服务器端口号")
    username: Mapped[str] = mapped_column(String(32), nullable=True, comment="客户端登录用户名")
    password: Mapped[str] = mapped_column(String(32), nullable=True, comment="客户端登录密码")
    willTopic: Mapped[str] = mapped_column(String(255), nullable=True, comment="遗嘱话题名称")
    willPayload: Mapped[str] = mapped_column(String(255), nullable=True, comment="遗嘱内容")
    willQoS: Mapped[int] = mapped_column(SmallInteger, nullable=True, comment="遗嘱话题质量")
    willRetain: Mapped[bool] = mapped_column(default=False, comment="遗嘱话题持久化")
